package setup;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JTextPane;
import javax.swing.SpinnerListModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.UIManager;

import adapter.Adapter;

public class StartMenu {

	private JFrame frame;
	private int players, money;
	private boolean fieldPlacement;
	private String rounds;
	private ResourceBundle msg;
	private Setup setup;

	/**
	 * Create the application.
	 */
	public StartMenu(Setup setup) {
		this.setup = setup;
		Adapter a = new Adapter();
		msg = a.getBundle();
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {		
		frame = new JFrame();
		frame.setBounds(100, 100, 354, 302);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);

		JTextPane txtpnIndstillingerMatador = new JTextPane();
		txtpnIndstillingerMatador.setEditable(false);
		txtpnIndstillingerMatador.setBackground(UIManager.getColor("Button.background"));
		txtpnIndstillingerMatador.setFont(new Font("Tahoma", Font.BOLD, 16));
		txtpnIndstillingerMatador.setText(msg.getString("Start_Menu"));
		txtpnIndstillingerMatador.setBounds(79, 11, 197, 26);
		frame.getContentPane().add(txtpnIndstillingerMatador);

		final JSlider slider = new JSlider();
		slider.setToolTipText(msg.getString("Choose_Players"));
		slider.setValue(2);
		slider.setPaintLabels(true);
		slider.setSnapToTicks(true);
		slider.setPaintTicks(true);
		slider.setMajorTickSpacing(1);
		slider.setMinimum(2);
		slider.setMaximum(6);
		slider.setBounds(171, 48, 136, 45);
		frame.getContentPane().add(slider);

		JTextPane txtpnAntalSpillere = new JTextPane();
		txtpnAntalSpillere.setEditable(false);
		txtpnAntalSpillere.setBackground(UIManager.getColor("Button.background"));
		txtpnAntalSpillere.setText(msg.getString("Number_Players"));
		txtpnAntalSpillere.setBounds(26, 54, 105, 20);
		frame.getContentPane().add(txtpnAntalSpillere);

		final JCheckBox chckbxTilfldigFeltplacering = new JCheckBox(msg.getString("Random_Fields"));
		chckbxTilfldigFeltplacering.setBounds(98, 162, 150, 23);
		frame.getContentPane().add(chckbxTilfldigFeltplacering);

		final JSpinner spinner = new JSpinner();
		spinner.setBackground(Color.WHITE);
		spinner.setModel(new SpinnerListModel(new String[] {msg.getString("Unlimited"), "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"}));
		spinner.setBounds(191, 104, 116, 20);
		frame.getContentPane().add(spinner);

		final JSpinner spinner_1 = new JSpinner();
		spinner_1.setBackground(Color.WHITE);
		spinner_1.setModel(new SpinnerNumberModel(30000, 10000, 250000, 5000));
		spinner_1.setBounds(228, 135, 79, 20);
		frame.getContentPane().add(spinner_1);

		JTextPane txtpnStartpenge = new JTextPane();
		txtpnStartpenge.setEditable(false);
		txtpnStartpenge.setBackground(UIManager.getColor("Button.background"));
		txtpnStartpenge.setText(msg.getString("Starting_Amount")+ " (10.000 - 250.000):");
		txtpnStartpenge.setBounds(26, 135, 183, 20);
		frame.getContentPane().add(txtpnStartpenge);

		JTextPane txtpnMaksAntalRunder = new JTextPane();
		txtpnMaksAntalRunder.setEditable(false);
		txtpnMaksAntalRunder.setBackground(UIManager.getColor("Button.background"));
		txtpnMaksAntalRunder.setText(msg.getString("Rounds"));
		txtpnMaksAntalRunder.setBounds(26, 104, 135, 20);
		frame.getContentPane().add(txtpnMaksAntalRunder);

		JTextPane txtpnMatadorByIoouteractive = new JTextPane();
		txtpnMatadorByIoouteractive.setEnabled(false);
		txtpnMatadorByIoouteractive.setEditable(false);
		txtpnMatadorByIoouteractive.setBackground(UIManager.getColor("Button.background"));
		txtpnMatadorByIoouteractive.setText("Matador by IOOuterActive");
		txtpnMatadorByIoouteractive.setBounds(98, 239, 178, 20);
		frame.getContentPane().add(txtpnMatadorByIoouteractive);

		JButton btnNewButton = new JButton(msg.getString("Start_Game"));
		btnNewButton.setBounds(120, 205, 89, 23);
		frame.getContentPane().add(btnNewButton);

		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e){
				players = slider.getValue(); // Antal spillere
				fieldPlacement = chckbxTilfldigFeltplacering.isSelected(); // Feltplacering random/ej random. True = random
				rounds = (String) spinner.getValue(); // Antal valgte runder
				money = (int) spinner_1.getValue(); // Antal startpenge
				setup.setChoices(players, money, fieldPlacement, rounds);
				frame.dispose(); // Lukker vinduet når der trykkes på "Start Spil"	
			}
		});	
		frame.setVisible(true);
	}	
}